package connection.layer;
import model.layer.User;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


public class Connection{

	    private static String SOAP_ACTION = "http://tempuri.org/IWcfFoodAndAllergies/";
	    private static  String METHOD_NAME;
	    private static final String NAMESPACE = "http://tempuri.org/";
	    private static final String URL = "http://192.168.0.18:2057/WcfFoodAndAllergies.svc";
	    

	    public Connection() {
	    	
		}
		public void InsertUser(User _user)
		{
			//METHOD_NAME = "InsertUser";
			METHOD_NAME = "InsertUserByProp"; 
			SOAP_ACTION = SOAP_ACTION + METHOD_NAME;
			SoapObject req = new SoapObject(NAMESPACE, METHOD_NAME);
			PropertyInfo ui = new PropertyInfo();
			ui.setName("userName");	
			ui.setValue(_user.getProperty(1));
			ui.setType(_user.getProperty(1).getClass());
			ui.setNamespace(NAMESPACE);
			req.addProperty(ui);
				
			PropertyInfo mi = new PropertyInfo();
			mi.setName("mac");
			mi.setValue(_user.getProperty(2));
			mi.setType(_user.getProperty(2).getClass());
			mi.setNamespace(NAMESPACE);
			req.addProperty(mi);
				
				
	
				
		
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		    envelope.dotNet = true;
		    envelope.implicitTypes = true;
		    envelope.setAddAdornments(false);
		    envelope.setOutputSoapObject(req);    
		    envelope.addMapping(NAMESPACE, "User", User.class);
		    HttpTransportSE ht = new HttpTransportSE(URL, 5000);
		    ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");    
				
		    try{
		    	ht.debug= true;
				ht.getServiceConnection().setRequestProperty("Content-Type", "text/xml");
				ht.call(SOAP_ACTION, envelope);
				envelope.getResponse();
				
		    }
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
}
	  

	 
	


